<template>
  <a-card :bordered="false">
<!--    tabs-->
    <a-tabs :defaultActiveKey="tabActive" @change='tabChange'>
      <a-tab-pane tab="入职" key="1"></a-tab-pane>
      <a-tab-pane tab="离职" key="2"></a-tab-pane>
      <a-tab-pane tab="岗位变动" key="3"></a-tab-pane>
    </a-tabs>
     <!-- 查询区域 -->
       <div class="table-page-search-wrapper">
         <a-form layout="inline" @keyup.enter.native="searchQuery">
           <a-row :gutter="24">
           <a-col :md="6" :sm="8">
                 <a-form-item label="姓名">
                   <a-input placeholder="请输入姓名" v-model="queryParamForm.name"></a-input>
                 </a-form-item>
           </a-col>
           <a-col :md="6" :sm="8">
                 <a-form-item label="身份证号">
                   <a-input placeholder="请输入身份证号" v-model="queryParamForm.sfzh"></a-input>
                 </a-form-item>
           </a-col>
           <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
               <a-col :md="6" :sm="12" >
                   <a-button type="primary"  style="left: 10px" @click="searchQuery" icon="search">查询</a-button>
                   <a-button type="primary"  @click="searchReset" icon="reload" style="margin-left: 8px;left: 10px">重置</a-button>
               </a-col>
            </span>
           </a-row>
         </a-form>
       </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">

      <a-button type="primary" v-if='tabActive==1' @click="handleRZ()">新增</a-button>
      <a-button type="primary" v-if='tabActive==2' @click="handleLZ()">新增</a-button>
      <a-button type="primary" v-if='tabActive==3' @click="handleGWBD()">新增</a-button>
      <a-divider type="vertical" />
      <a-button type="primary" @click="handleWDSQ()">已提交</a-button>
      <a-modal :visible="wdsqVisible" title="已提交" width="80%" @cancel="wdsqVisible = false">
         <template #footer>
          <a-button key="back" @click="wdsqVisible = false">关闭</a-button>
        </template>
        <applyList ref="applyRef"  :tabType='tabActive' :type="type"></applyList>
      </a-modal>
      <a-divider type="vertical" />
      <a-button type="primary" v-if='tabActive==2' @click="departurePerBtn">已离职人员</a-button>
      <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('YGDAB')">导出</a-button>
      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
       -->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width: 80px; font-size: 12px; font-style: italic"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <!-- <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span> -->
      </a-table>
    </div>
    <RZ :visible="rzVisible" @ok="saveRz" @close="rzVisible = false" :rows="selectionRows" v-on:RZC='RZC' />
    <LZ v-if="lzVisible" :visible="lzVisible" @ok="saveLz" @close="lzVisible = false" :rows="selectionRows" v-on:RZC='RZC' />
    <YLZPER v-if="ylzVisible" :YLZData="YLZPERData" @close="ylzVisible = false" v-on:ylzChiid='ylzChiid'></YLZPER>
    <GWBD :visible="gwbdVisible" @ok="saveGWBD" @close="gwbdVisible = false" :rows="selectionRows" v-on:RZC='RZC' />

    <ygdab-modal ref="modalForm" @ok="modalFormOk"></ygdab-modal>
  </a-card>
</template>

<script>

import { getAction,putAction } from '@/api/manage'
import '@/assets/less/TableExpand.less'
import applyList from '@/views/activiti/applyList'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import YgdabModal from './modules/YgdabModal'
import RZ from './components/RZ.vue'
import LZ from './components/LZ.vue'
import YLZPER from './components/YLZPER.vue'
import GWBD from './components/GWBD.vue'
import { axios } from '@/utils/request'
import { postAction } from '../../api/manage'
export default {
  name: 'YgdabList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    YgdabModal,
    RZ,
    LZ,
    GWBD,
    applyList,
    YLZPER
  },
  data() {
    return {
      type: "员工入职申请,员工离职申请,员工调动变动申请",
      wdsqVisible: false,
      rzVisible: false,
      lzVisible: false,
      gwbdVisible: false,
      ylzVisible:false,
      YLZPERData:{},
      description: 'YGDAB管理页面',
      // 表头
      columns: [
        {
          title: 'id',
          align: 'center',
          dataIndex: 'id',
        },
        {
          title: 'name',
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: 'borth',
          align: 'center',
          dataIndex: 'borth',
        },
        {
          title: 'sex',
          align: 'center',
          dataIndex: 'sex',
        },
        {
          title: 'mzcode',
          align: 'center',
          dataIndex: 'mzcode',
        },
        {
          title: 'sfzh',
          align: 'center',
          dataIndex: 'sfzh',
        },
        {
          title: 'hyqk',
          align: 'center',
          dataIndex: 'hyqk',
        },
        {
          title: 'hjdz',
          align: 'center',
          dataIndex: 'hjdz',
        },
        {
          title: 'jtdz',
          align: 'center',
          dataIndex: 'jtdz',
        },
        {
          title: 'zzmm',
          align: 'center',
          dataIndex: 'zzmm',
        },
        {
          title: 'xl1',
          align: 'center',
          dataIndex: 'xl1',
        },
        {
          title: 'zy1',
          align: 'center',
          dataIndex: 'zy1',
          colSpan:0,
          customRender:(value)=>{
              let obj={
                children:value,
                attrs:{}
              }
              obj.attrs.colSpan=0;
              return obj;
          }
        },
        {
          title: 'bysj1',
          align: 'center',
          dataIndex: 'bysj1',
          colSpan:0,
          customRender:(value)=>{
              let obj={
                children:value,
                attrs:{}
              }
              obj.attrs.colSpan=0;
              return obj;
          }
        },
        {
          title: 'byyx1',
          align: 'center',
          dataIndex: 'byyx1',
          colSpan:0,
          customRender:(value)=>{
              let obj={
                children:value,
                attrs:{}
              }
              obj.attrs.colSpan=0;
              return obj;
          }
        },
        {
          title: 'xl2',
          align: 'center',
          dataIndex: 'xl2',
          colSpan:0,
          customRender:(value)=>{
              let obj={
                children:value,
                attrs:{}
              }
              obj.attrs.colSpan=0;
              return obj;
          }
        },
        {
          title: 'zy2',
          align: 'center',
          dataIndex: 'zy2',
          colSpan:0,
          customRender:(value)=>{
              let obj={
                children:value,
                attrs:{}
              }
              obj.attrs.colSpan=0;
              return obj;
          }
        },
        {
          title: 'bysj2',
          align: 'center',
          dataIndex: 'bysj2',
          colSpan:0,
          customRender:(value)=>{
              let obj={
                children:value,
                attrs:{}
              }
              obj.attrs.colSpan=0;
              return obj;
          }
        },
        {
          title: 'byyx2',
          align: 'center',
          dataIndex: 'byyx2',
          colSpan:0,
          customRender:(value)=>{
              let obj={
                children:value,
                attrs:{}
              }
              obj.attrs.colSpan=0;
              return obj;
          }
        },
        {
          title: 'zj',
          align: 'center',
          dataIndex: 'zj',
          colSpan:0,
          customRender:(value)=>{
              let obj={
                children:value,
                attrs:{}
              }
              obj.attrs.colSpan=0;
              return obj;
          }
        },
        {
          title: 'jstc',
          align: 'center',
          dataIndex: 'jstc',
          colSpan:0,
          customRender:(value)=>{
              let obj={
                children:value,
                attrs:{}
              }
              obj.attrs.colSpan=0;
              return obj;
          }
        },
        {
          title: 'zc',
          align: 'center',
          dataIndex: 'zc',
          colSpan:0,
          customRender:(value)=>{
              let obj={
                children:value,
                attrs:{}
              }
              obj.attrs.colSpan=0;
              return obj;
          }
        },
        {
          title: 'phone1',
          align: 'center',
          dataIndex: 'phone1',
          colSpan:0,
          customRender:(value)=>{
              let obj={
                children:value,
                attrs:{}
              }
              obj.attrs.colSpan=0;
              return obj;
          }
        },
        {
          title: 'phone2',
          align: 'center',
          dataIndex: 'phone2',
          colSpan:0,
          customRender:(value)=>{
              let obj={
                children:value,
                attrs:{}
              }
              obj.attrs.colSpan=0;
              return obj;
          }
        },
        {
          title: 'isnmg',
          align: 'center',
          dataIndex: 'isnmg',
        },
        {
          title: 'jyyx',
          align: 'center',
          dataIndex: 'jyyx',
        },
        {
          title: 'qzyq',
          align: 'center',
          dataIndex: 'qzyq',
        },
        {
          title: 'topdwid',
          align: 'center',
          dataIndex: 'topdwid',
        },
        {
          title: 'dwid',
          align: 'center',
          dataIndex: 'dwid',
        },
        {
          title: 'dwname',
          align: 'center',
          dataIndex: 'dwname',
        },
        {
          title: 'ksname',
          align: 'center',
          dataIndex: 'ksname',
        },
        {
          title: 'bmname',
          align: 'center',
          dataIndex: 'bmname',
        },
        {
          title: 'workaddr',
          align: 'center',
          dataIndex: 'workaddr',
        },
        {
          title: 'gwid',
          align: 'center',
          dataIndex: 'gwid',
        },
        {
          title: 'gwname',
          align: 'center',
          dataIndex: 'gwname',
        },
        {
          title: 'gzfs',
          align: 'center',
          dataIndex: 'gzfs',
        },
        {
          title: 'gwlb',
          align: 'center',
          dataIndex: 'gwlb',
        },
        {
          title: 'zwgz',
          align: 'center',
          dataIndex: 'zwgz',
        },
        {
          title: 'paysmonth',
          align: 'center',
          dataIndex: 'paysmonth',
        },
        {
          title: 'daysmonth',
          align: 'center',
          dataIndex: 'daysmonth',
        },
        {
          title: 'workstate',
          align: 'center',
          dataIndex: 'workstate',
        },
      ],
      url: {
        list: '/bj/ygdab/list',
        delete: '/bj/ygdab/delete',
        deleteBatch: '/bj/ygdab/deleteBatch',
        exportXlsUrl: '/bj/ygdab/exportXls',
        importExcelUrl: 'bj/ygdab/importExcel',
      },
      dictOptions: {},
      rows: [],
      tabActive:'1',
      dataSource:[],
      queryParamForm:[],
      ipagination:{}
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  created() {
    var params={
         pageNo:1,
          pageSize:10
        }
    this.getList(this.tabActive,params)
  },
  methods: {
    RZC(RZC){
      var params={
         pageNo:1,
          pageSize:10
        }
      this.getList(this.tabActive,params)
    },
    handleTableChange(pagination, filters, sorter){
        const pager = { ...this.ipagination };
        pager.current = pagination.current;
        this.ipagination = pager;
        var params={
          pageNo:pagination.current,
          pageSize:pagination.pageSize
        }
        this.getList(this.tabActive,params)
    },
    //获取表格数据
    getList(type,params){
      getAction(this.url.list,Object.assign({type:type},this.queryParamForm,params)).then((res)=>{
        //console.log('返回的数据：'+JSON.stringify(res))
        if (res.success) {
          let dataSource = res.result
          if (!(dataSource instanceof Array)) {
            const pagination = { ...this.ipagination };
            pagination.total = res.result.total;
            this.dataSource = res.result.records;
            this.ipagination = pagination;
            this.onClearSelected()
          }
        }
      });
    },

    //已离职人员弹窗
    departurePerBtn(){
      this.ylzVisible = true;
      this.YLZPERData = {
        visible:true,
        rows:[]
      }
    },
    ylzChiid(ylzChiid){
      this.ylzVisible = false;
    },
    handleRZ() {
      if (this.selectionRows.length < 1) {
        this.$message.error('没有人员')
        return
      }
      this.rzVisible = true
    },
    handleLZ() {
      if (this.selectionRows.length < 1) {
        this.$message.error('没有人员')
        return
      }
      this.lzVisible = true
    },
    handleGWBD() {
      if (this.selectionRows.length > 1) {
        this.$message.error('岗位变动只能选择单人')
        return
      }else if(this.selectionRows.length < 1){
        this.$message.error('没有人员')
        return
      }
      this.gwbdVisible = true
    },
    handleWDSQ() {
          this.wdsqVisible = true
     },
    saveRz(rows) {
      console.log("rows:"+JSON.stringify(rows));
      return false;
      postAction('/bj/bjIdcardfk/addRuzhi', { ruzhi: rows }).then((res) => {
        if (res.success) {
          this.$message.success('成功')
          this.rzVisible = false
        } else {
          this.$message.error('失败')
        }
      })
    },
    saveLz(form) {
      postAction('/bj/bjIdcardfk/addLizhi', form).then((res) => {
        if (res.success) {
          this.$message.success('成功')
          this.lzVisible = false
        } else {
          this.$message.error('失败')
        }
      })
    },
    saveGWBD(form) {
      postAction('/bj/bjIdcardfk/addBiandong', { ids: form.ids, biandongjson: JSON.stringify(form) }).then((res) => {
        if (res.success) {
          this.$message.success('成功')
          this.gwbdVisible = false
        } else {
          this.$message.error('失败')
        }
      })
      },
    initDictConfig() {},
    //点击切换tabs
    tabChange(val){
      console.log(val)
      this.tabActive=val;
      this.getList(val)
    },
    //查询
    searchQuery(){
      this.getList(this.tabActive)
    },
    //重置搜索表单
    searchReset() {
      this.queryParamForm={};
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>